package com.niit.listener;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JTable;

import com.niit.dao.BookDao;
import com.niit.dao.impl.BookDaoImpl;
import com.niit.view.MainView;

public class DelectListener extends MouseAdapter{
	private MainView view;
	private BookDao dao ;
	public DelectListener(MainView view){
		this.view = view;
		dao = new BookDaoImpl();
	}
	//当点击删除时
	@Override
	public void mouseClicked(MouseEvent arg0) {
		JTable dataTable = view.getDataTable();
		int selectedColumn = dataTable.getSelectedColumn();
		int row = dataTable.getSelectedRow();
		//拿到选中行的id值
		int value = (int) dataTable.getValueAt(row, 0);
		dao.delete(value);
		System.out.println("删除ID号"+value+"数据成功");
		view.dispose();
		new MainView(null);
	}
}
